package com.dustedpixels.jasmin.memory;

import com.dustedpixels.jasmin.memory.impl.RAM16x8;
import com.dustedpixels.jasmin.memory.impl.RAMBlock16x8;
import com.dustedpixels.jasmin.memory.impl.ROM16x8;
import com.dustedpixels.jasmin.memory.impl.SelectMemory16x8;

/**
 * Global package methods.
 */
public final class MemoryPackage {
    /**
     * Creates and returns new 64Kb Random Access Memory.
     * 
     * @return The memory.
     */
    public static Memory16x8 createRAM16x8() {
        return RAM16x8.create();
    }

    /**
     * Creates and returns new 64Kb Random Access Memory backed by specified
     * 64Kb array.
     * 
     * @param array The backing array.
     * @return The memory.
     */
    public static Memory16x8 createRAM16x8(byte[] array) {
        return RAM16x8.create(array);
    }

    /**
     * Creates new Random Access Memory with address bus width equal to
     * addressBits. The actual address is masked with (1^addressBits)-1.
     * 
     * @param addressBits The address bus width.
     * @return The memory.
     */
    public static Memory16x8 createRAM16x8(int addressBits) {
        return RAMBlock16x8.create(addressBits);
    }

    /**
     * Creates new Random Access Memory backed by specified byte array, with
     * specified address bus width. The array length should be 1^addressBits.
     * The actual address is masked with (1^addressBits)-1.
     * 
     * @param addressBits The address bus width.
     * @param array The backing array.
     * @return The memory.
     */
    public static Memory16x8 createRAM16x8(int addressBits, byte[] array) {
        return RAMBlock16x8.create(addressBits, array);
    }

    /**
     * Wraps specified memory with Read Only Memory.
     * 
     * @param ram The memory to wrap.
     * @return The Read Only Memory.
     */
    public static Memory16x8 asROM(Memory16x8 ram) {
        return ROM16x8.create(ram);
    }

    /**
     * Creates a memory consists of fixed-size memory blocks. The length of the
     * array with memory blocks should be 1^selectorBits.
     * 
     * @param selectorBits The number of selector bits.
     * @param memories The memory blocks.
     * @return The memory
     */
    public static Memory16x8 createSelectMemory(int selectorBits,
            Memory16x8[] memories) {
        return SelectMemory16x8.create(selectorBits, memories);
    }
}
